#include "findInTable.h"


int findInTable(ConstTable Table, struct ConstInfo_Element Const) {

	int retVal = -1;
	ConstTable ::const_iterator it;
	
	for(it = Table.begin(); it != Table.end(); ++it) {
		if(Const.ConstType == it->second.ConstType) {
			switch(it->second.ConstType) {
				case const_UTF8:
					if(strcmp(Const.ConstValue.const_UTF8, it->second.ConstValue.const_UTF8) == 0)
						retVal = it->first;
					break;
				case const_Int: 
					if(Const.ConstValue.const_float == Const.ConstValue.const_Int)
						retVal = it->first;
					break;
				case const_float:
					if(Const.ConstValue.const_float == Const.ConstValue.const_Int)
						retVal = it->first;
					break;
				case const_string:
					if(Const.ConstValue.const_stringN == it->second.ConstValue.const_nat_NameN)
						retVal = it->first;
					break;

				case const_class:
					if(Const.ConstValue.const_mf_ClassN == it->second.ConstValue.const_mf_ClassN) {
						retVal = it->first;
					}
					break;
				case const_methodref:
				case const_field:
					if(Const.ConstValue.const_mf_ClassN == it->second.ConstValue.const_mf_ClassN && Const.ConstValue.const_mf_NameAndTypeN == it->second.ConstValue.const_mf_NameAndTypeN) {
						retVal = it->first;
					}
					break;
				case const_nameandtype:
					if(Const.ConstValue.const_nat_DescrN == it->second.ConstValue.const_nat_DescrN && Const.ConstValue.const_nat_NameN == it->second.ConstValue.const_nat_NameN) {
						retVal = it->first;
					}				
					break;
				default:
					retVal = -1;
			}
		} 
	}
   return retVal;
}